<?php

namespace App\Exports;

use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
use Maatwebsite\Excel\Concerns\WithTitle;

class MultipleSheetsExport implements WithMultipleSheets
{
    use Exportable;

    protected $data1;
    protected $data2;
    protected $data3;
    protected $data4;
    public function __construct($data1, $data2, $data3, $data4)
    {
        $this->data1 = $data1;
        $this->data2 = $data2;
        $this->data3 = $data3;
        $this->data4 = $data4;
    }

    public function sheets(): array
    {
        $sheets = [];
        $sheets[] = new SheetExport("工业设计", $this->data1);
        $sheets[] = new SheetExport("机械设计制造及其自动化", $this->data2);
        $sheets[] = new SheetExport("生物工程", $this->data3);
        $sheets[] = new SheetExport("机械设计制造及其自动化+生物工程", $this->data4);

        return $sheets;
    }
}

class SheetExport implements FromCollection, WithTitle
{
    protected $name;
    protected $data;
    public function __construct($name,$data)
    {
        $this->name = $name;
        $this->data = $data;
    }
    public function collection(): Collection
    {
        return collect($this->data);
    }
    public function title(): string
    {
        return $this->name;
    }
}

